import { resetRouter, routes } from "@/router";
import { defineStore } from "pinia";
import { ref } from "vue";
import type { RouteRecordRaw } from "vue-router";

// routes是静态列表，默认就有
export const useMenuStore = defineStore("hm-menu", () => {
    // 用来渲染的菜单列表
  const menuList = ref<RouteRecordRaw[]>([...routes])
// 动态列表，根据用户权限过滤，将过滤后的动态路由列表添加到menuList中
  const setMenuList = (filterRoutes: RouteRecordRaw[]) => {
    menuList.value = [...menuList.value, ...filterRoutes]
  }
  const clearMenuList = () => {
    menuList.value = [...routes]
    resetRouter()
  }
  return {
    menuList,
    setMenuList,
    clearMenuList
  }
})